<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="web/include_web::header"></head>
<body>
<nav th:include="web/include_web::nav"  class="navbar navbar-default navbar-custom navbar-fixed-top" ></nav>
<header class="intro-header" style="background-image: url('/img/blog/bg.jpg') ; height: 50px">

</header>

<!-- Main Content -->
<div class="container">
	<div class="row">
		<h2>租车订单</h2>
	</div>
	<!--<div style="float:right ">
		<form class="form-search">
			<input class="input-medium search-query" type="text" /> <button type="submit" class="btn">查找</button>
		</form>
	</div>-->

</div>
<!-- Main Content -->
<div class="container">
	<input id="userId" name="userId" th:value="${userid}" type="hidden">
	<div class="row">
		<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
			<div id="incomeNum">
				<div id="incomeNumfluid" class="container-fluid">
					<table class="table">
						<thead>
						<tr>
							<th>
								序号
							</th>
							<th>
								订单号
							</th>
							<th>
								车辆
							</th>
							<th>
								起租日
							</th>
							<th>
								还车日
							</th>
							<th>
								总价
							</th>
							<th>
								状态
							</th>
						</tr>
						</thead>
						<tbody id="tb_body">

						</tbody>
					</table>
				</div>
			</div>
			<div class="clearfix">
				<p id="flagLoaded" style="display: none; text-align: center;">已全部加载</p>
				<a id="flagLoad" style="display: none;" class="btn btn-secondary float-right"
				   href="javascript:void(0)" onclick="nextPage()">更早 &rarr;</a>
			</div>
		</div>
	</div>
</div>
</body>
<div th:include="web/include_web::footer"></div>
<script type="text/javascript">
	var total;
	$(function(){
		bindList(0);

	});
	function bindList(offset) {
		$.ajax({
			url:'/weborder/list?userId='+$("#userId").val(),
			method:'get',
			dataType:'json',
			success:function(data){
				var total =data.length;
				var date = new Date();
				console.log(date.toLocaleDateString());
				var htmlText = "";
				for (i = 0; i < total; i++) {
					htmlText += '<tr><td>'+(i+1)+'</td><td>'+data[i].id+'</td>' +
							'<td>'+data[i].carName+'</td><td>'+/\d{4}-\d{1,2}-\d{1,2}/g.exec(data[i].beginDate)+'</td><td>'+/\d{4}-\d{1,2}-\d{1,2}/g.exec(data[i].endDate)+'</td>' +
							'<td>'+data[i].totalPrice+'</td>';
					console.log(judgeTime(data[i].endDate));
					if(data[i].yxbz=="N"){
						htmlText+='<td>已取消</td></tr>';
					}else if(judgeTime(data[i].endDate)){
						htmlText+='<td>已完成</td></tr>';
					}else{
						htmlText+='<td><button class="btn small" onclick="cancelOrder('+data[i].id+')" type="button">取消预定</button></td></tr>';
					}
				}
				$("#tb_body").append(htmlText);
			}
		});
	}

	function judgeTime(time){
		var strtime = time.replace("/-/g", "/");//时间转换
	//时间
		var date1=new Date(strtime);
	//现在时间
		var date2=new Date();
	//判断时间是否过期
		return date1<date2?true:false;
	}
	function cancelOrder(id) {
		parent.layer.confirm('确定要取消预定？', {
			btn : [ '确定', '取消' ]
		}, function() {
			$.ajax({
				url : "/weborder/update",
				type : "post",
				data : {
					'id' : id,
					'yxbz': 'N'
				},
				success : function(r) {
					if (r.code==0) {
						layer.msg('取消成功');
						$("#tb_body").html("");
						bindList(0);
					}else{
						layer.msg(r.msg);
					}
				}
			});
		})
	}
</script>


</html>
